package com.hmall.trade.listener;

import com.hmall.common.constant.MQConstant;
import com.hmall.trade.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class OrderPayListener {
    @Autowired
    private IOrderService orderService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(MQConstant.ORDER_PAY_QUEUE),
            exchange = @Exchange(MQConstant.PAY_TOPIC),
            key = MQConstant.ORDER_PAY_KEY
    ))
    public void onOrderPays(String msg){
        log.info("收到了订单支付完成的消息：{}", msg);
        orderService.markOrderPaySuccess(Long.parseLong(msg));
    }
}
